home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / tests / thrash / thrash.c < prev   
Encoding:
C/C++ Source or Header  |  1992-01-22  |  2.6 KB  |  107 lines

  1. /* 
  2.  * thrash.c --
  3.  *
  4.  *    Test program to cause lots of paging.
  5.  *
  6.  * Copyright 1991 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that this copyright
  10.  * notice appears in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /r3/kupfer/spriteserver/tests/thrash/RCS/thrash.c,v 1.3 92/01/22 13:22:14 kupfer Exp $ SPRITE (Berkeley)";
  18. #endif /* not lint */
  19.  
  20. #include <mach.h>
  21. #include <ctype.h>
  22. #include <status.h>
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <sys/types.h>
  26. #include <test.h>
  27. #include <vm.h>
  28.  
  29. /* 
  30.  * Name of the big mapped file to create.
  31.  */
  32. #define FILE_NAME    "DummyFile"
  33.  
  34. /* 
  35.  * Number of iterations to walk through the file.
  36.  */
  37. #define ITERATIONS    3
  38.  
  39. Boolean gentle = FALSE;        /* pause between faults? */
  40.  
  41. /* Forward references */
  42.  
  43. static void MakeFile _ARGS_((char *fileName));
  44.  
  45. main(argc, argv)
  46.     int argc;
  47.     char *argv[];
  48. {
  49.     int bufferLength = 32 * 1024 * 1024;
  50.     char *buffer;
  51.     int iter;            /* iteration count */
  52.     char *cp;
  53.     ReturnStatus status;
  54.  
  55.     if (argc > 1) {
  56.     gentle = TRUE;
  57.     }
  58.  
  59.     status = Vm_MapFile(FILE_NAME, FALSE, (off_t)0,
  60.             (vm_size_t)bufferLength, &buffer);
  61.     if (status != SUCCESS) {
  62.     Test_PutMessage("Couldn't map file: ");
  63.     Test_PutMessage(Stat_GetMsg(status));
  64.     Test_PutMessage("\n");
  65.     goto bailOut;
  66.     }
  67.  
  68.     /* 
  69.      * Touch all the pages in the file, then wait a bit before 
  70.      * repeating.  Verify that the value you wrote is still there.  
  71.      * Pause before touching each page so as to reduce the load on 
  72.      * Mach.  (Running at full speed eventually causes the ethernet 
  73.      * interface to get a bus error, at least on a sun3.)
  74.      */
  75.     for (iter = 0; iter < ITERATIONS; iter++) {
  76.     Test_PutMessage("iteration ");
  77.     Test_PutDecimal(iter+1);
  78.     Test_PutMessage(": ");
  79.     for (cp = buffer; cp < buffer + bufferLength;
  80.          cp += vm_page_size) {
  81.         if (gentle) {
  82.         msleep(250);
  83.         }
  84.         if ((cp - buffer) % (20 * vm_page_size) == 0) {
  85.         Test_PutDecimal(100 * (unsigned)(cp - buffer) / bufferLength);
  86.         Test_PutMessage(" ");
  87.         }
  88.         if (iter > 0) {
  89.         if (*cp != 'a' + iter - 1) {
  90.             Test_PutMessage("thrash: wrong value (");
  91.             Test_PutHex(*(unsigned char *)cp);
  92.             Test_PutMessage(") at offset ");
  93.             Test_PutHex(cp - buffer);
  94.             Test_PutMessage("\n");
  95.         }
  96.         }
  97.         *cp = 'a' + iter;
  98.     }
  99.  
  100.     Test_PutMessage("pausing\n");
  101.     msleep(1000);
  102.     }
  103.  
  104.  bailOut:
  105.     exit(0);
  106. }
  107.